#include "UserService.hpp"

bool UserService::Login(int id, std::string name, std::string password)
{
    std::cout << "正在处理登录业务" << std::endl;
    std::cout << "name :" << name << " " << password;
    return true;
}

void UserService::Login(::google::protobuf::RpcController *controller,
           const ::RpcProto::LoginRequest *request,
           ::RpcProto::LoginResponse *response,
           ::google::protobuf::Closure *done)
{
    // 其他模块通过caller调用本login ，request已经反序列好了
    int id = request->id();
    std::string name = request->name().c_str();
    std::string password = request->password().c_str();
    // 调用本地的login
    bool ret = Login(id, name, password);
    // 构造返回对象
    RpcProto::ReturnCode *returncode = response->mutable_returncode();
    if (ret == true)
    {
        returncode->set_errcode(0);
        returncode->set_errmessgae("");
        response->set_successmessage("call Login succussful");
    }
    else if (ret == false)
    {
        returncode->set_errcode(1);
        returncode->set_errmessgae("call Login fail");
        response->set_successmessage("");
    }
    // 发送回调用模块
    done->Run();
}